﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.mMall.Buyer
{
    public partial class mfSetInnerPayPwd : msBsc.Cls.mbPCustom
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public override void DoAction()
        {
            if (this.strAction == "SetPayPwdInfo")
            {
                SetInnerPayPwd();
            }

            if (this.strAction == "IsSetedPayPwd")
            {
                IsSetedPayPwd();
            }
        }

        private void SetInnerPayPwd()
        {
            string userpwd = this.GetParamHtValue("userPayPwd");

            if (string.IsNullOrEmpty(userpwd))
            {
                this.ExecJScript(@"ShowErrMsg(""pwdUserPayPwd"", ""notice-msg-aliaccount"", ""支付密码不能为空"");");
                return;
            }

            if (userpwd.Length < 6 || userpwd.Length > 16)
            {
                this.ExecJScript(@"ShowErrMsg(""pwdUserPayPwd"", ""notice-msg-aliaccount"", ""支付密码必须在6~16位之间"");");
                return;
            }

            string[] result;

            using (msBsc.AppLogic.DataAlc.CBizCustomerRegister objCBizCustomerRegister = new AppLogic.DataAlc.CBizCustomerRegister())
            {
                result = objCBizCustomerRegister.SetInnerPayPwd(userpwd, true);
            }

            if (result[0] == "TRUE"
                && result[1] == "OK")
            {
                this.ExecJScript(@"SetPayPwdSuccess()");
                return;
            }

            this.ExecJScript(@"ShowErrMsg(""pwdUserPayPwd"", ""notice-msg-aliaccount"", '" + result[1] + "');");
        }

        private void IsSetedPayPwd()
        {
            using (msBsc.AppLogic.DataAlc.CBizCustomerRegister objCBizCustomerRegister = new AppLogic.DataAlc.CBizCustomerRegister())
            {
                System.Data.DataSet ds = objCBizCustomerRegister.DataObj.QueryBySQL(@"SELECT CUSTOMER_PAY_INNERPWD FROM DJK_CUSTOMER_REGISTER WHERE CUSTOMER_REGISTER_ID='" + msBsc.SvRef.UserInfo.Operator + "'");

                if (ds != null
                    && ds.Tables[0].Rows.Count > 0
                    && ds.Tables[0].Rows[0]["CUSTOMER_PAY_INNERPWD"] != DBNull.Value)
                {
                    this.ExecJScript(@"alert(""您已设置支付密码。若需要修改支付密码，请在个人中心选择修改支付密码，进行修改。"");window.location.href='/mb_UserInfo.htm'");
                }
            }
        }
    }
}